import pypinyin


class province:
    name = ""
    id = ""
    first_letter = ""
    url = ""

    def __init__(self, province_name, province_id, province_first_letter="", province_url=""):
        self.name = province_name
        self.id = province_id
        self.first_letter = province_first_letter
        self.url = province_url

    def get_first_letter(self):
        if self.first_letter is None or self.first_letter == "":
            self.first_letter = pypinyin.pinyin(self.name, style=pypinyin.FIRST_LETTER)[0][0].upper()

    def to_dict(self):
        return {"name": self.name, "id": self.id, "first_letter": self.first_letter, "url": self.url}
